<template>
  <ContentWrap>
    <!-- 搜索工作栏 -->
    <el-form
      class="-mb-15px"
      :model="queryParams"
      ref="queryFormRef"
      :inline="true"
      label-width="68px"
    >
     <el-form-item label="时间" prop="dateString">
        <el-date-picker
            v-model="queryParams.dateString"
            value-format="YYYY-MM-DD"
            type="daterange"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            class="!w-240px"
          />
      </el-form-item>
      <el-form-item>
        <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
        <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
      </el-form-item>
    </el-form>
  </ContentWrap>

  <!-- 列表 -->
  <ContentWrap>
    <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
      <el-table-column label="部门" align="center" prop="deptName" />
      <el-table-column label="绩效" align="center" prop="score" />
      <el-table-column label="总发布数" align="center" prop="count" />
    </el-table>
    <!-- 分页 -->
    <Pagination
      :total="total"
      v-model:page="queryParams.pageNo"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </ContentWrap>

</template>

<script setup lang="ts">
import * as ContentApi from '@/api/cms/content'

import { formatDate, addTimeByDay } from '@/utils/formatTime'

/** 用户绩效 列表 */
defineOptions({ name: 'UserContentScore' })
const loading = ref(true) // 列表的加载中
const list = ref<any[]>([]) // 列表的数据
const total = ref(0) // 列表的总页数
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  dateString: []
})
const initTime = () => {
  const now = formatDate(new Date(), 'YYYY-MM-DD')
  const begin = addTimeByDay(new Date(), -30, 'YYYY-MM-DD')
  queryParams.dateString = [begin, now]
}
const initQuery = () => {
  initTime()
  handleQuery()
}
const queryFormRef = ref() // 搜索的表单

/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await ContentApi.getDeptScoreStatPage(queryParams)
    list.value = data
    total.value = data.length
  } finally {
    loading.value = false
  }
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.pageNo = 1
  getList()
}

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value.resetFields()
  handleQuery()
}

/** 初始化 **/
onMounted(() => {
  initQuery()
})
</script>
